home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTMULTI.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  6KB  |  289 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet multicast version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?
  44. handle        dw    ?
  45.  
  46. multi_count    dw    -1        ;default to not setting any.
  47.  
  48. signature    db    'PKT DRVR',0
  49. signature_len    equ    $-signature
  50.  
  51. no_signature_msg    db    "No packet driver at that address",'$'
  52. usage_msg    db    "usage: pktmulti <packet_int_no> [-f <filename> | <address> ...]",'$'
  53. file_not_found    db    "File not found",'$'
  54. read_trouble    db    "Trouble reading the file",'$'
  55.  
  56. line_buffer    db    128 dup(?)
  57.  
  58. usage_error:
  59.     mov    dx,offset usage_msg
  60. error:
  61.     mov    ah,9
  62.     int    21h
  63.     int    20h
  64.  
  65. start_1:
  66.     cld
  67.  
  68.     mov    dx,offset copyleft_msg
  69.     mov    ah,9
  70.     int    21h
  71.  
  72.     mov    si,offset phd_dioa+1
  73.     call    skip_blanks
  74.     cmp    al,CR            ;end of line?
  75.     je    usage_error
  76.  
  77.     mov    di,offset packet_int_no
  78.     call    get_number
  79.  
  80.     call    skip_blanks
  81.     cmp    al,CR            ;did they just give an interrupt?
  82.     jne    have_arguments
  83.     jmp    start_noset        ;yes, don't set any addresses.
  84. have_arguments:
  85.  
  86.     mov    al,[si]            ;did the give the packet inline?
  87.     cmp    al,'-'            ;did they specify a switch?
  88.     jne    not_switch
  89.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  90.     jne    usage_error        ;no, must be an error.
  91.     add    si,2
  92.     call    skip_blanks
  93.     jmp    start_file
  94. not_switch:
  95.     jmp    start_inline        ;yes.
  96.  
  97. start_file:
  98.     mov    dx,si            ;remember where the filename starts.
  99. start_3:
  100.     lodsb
  101.     cmp    al,' '
  102.     je    start_4
  103.     cmp    al,CR
  104.     jne    start_3
  105. start_4:
  106.     dec    si
  107.     mov    byte ptr [si],0
  108.  
  109. ;read the packet bytes from the named file.
  110.  
  111.     mov    ax,3d00h        ;open for reading.
  112.     int    21h
  113.     mov    dx,offset file_not_found
  114.     jc    error
  115.     mov    handle,ax
  116.  
  117.     mov    di,offset our_buffer
  118. start_line:
  119.     mov    si,offset line_buffer
  120. again_line:
  121.     mov    ah,3fh            ;read a single character.
  122.     mov    bx,handle
  123.     mov    cx,1
  124.     mov    dx,si
  125.     int    21h
  126.     mov    dx,offset read_trouble
  127.     jc    error
  128.     cmp    ax,1            ;did we actually read one?
  129.     jne    start_file_eof
  130.  
  131.     lodsb                ;get the character we just read.
  132.     cmp    al,LF            ;got the LF?
  133.     jne    again_line        ;no, read again.
  134.  
  135.     mov    si,offset line_buffer
  136. again_chars:
  137.     push    ds
  138.     pop    es
  139.     call    get_eaddr        ;get_eaddr increments di.
  140.     call    skip_blanks
  141.     cmp    al,CR
  142.     jne    again_chars        ;keep going to the end.
  143.  
  144.     jmp    start_line
  145.  
  146. start_file_eof:
  147.     mov    [si],byte ptr CR    ;add an extra LF, just in case.
  148.     mov    si,offset line_buffer    ;and get the last address, just
  149.     push    ds
  150.     pop    es
  151.     call    get_eaddr        ;  in case they didn't CRLF after it.
  152. start_file_1:
  153.     mov    ah,3eh            ;close the file.
  154.     mov    bx,handle
  155.     int    21h
  156.     jmp    short start_gotit
  157.  
  158. start_inline:
  159. ;read the multicast addresses off the command line.
  160.     mov    di,offset our_buffer
  161. start_2:
  162.     push    ds
  163.     pop    es
  164.     call    get_eaddr        ;get an address.
  165.     call    skip_blanks
  166.     cmp    al,CR
  167.     jne    start_2            ;keep going to the end.
  168.  
  169. start_gotit:
  170.  
  171.     sub    di,offset our_buffer
  172.     mov    multi_count,di
  173.  
  174. start_noset:
  175.  
  176.     mov    ah,35h            ;get their packet interrupt.
  177.     mov    al,packet_int_no
  178.     int    21h
  179.     mov    their_isr.offs,bx
  180.     mov    their_isr.segm,es
  181.  
  182.     lea    di,3[bx]
  183.     mov    si,offset signature
  184.     mov    cx,signature_len
  185.     repe    cmpsb
  186.     je    signature_ok
  187.     jmp    no_signature_err
  188. signature_ok:
  189.  
  190.     push    ds
  191.     mov    ax,1ffh            ;driver_info
  192.     int_pkt
  193.     pop    ds
  194.     call    fatal_error
  195.  
  196.     mov    ah,2            ;access all packets.
  197.     mov    al,ch            ;their class from driver_info().
  198.     mov    bx,dx            ;their type from driver_info().
  199.     mov    dl,cl            ;their number from driver_info().
  200.     mov    cx,0            ;type length of zero.
  201.     push    cs            ;es:di -> our receiver.
  202.     pop    es
  203.     mov    di,offset our_recv
  204.     int_pkt
  205.     call    fatal_error
  206.     mov    handle,ax
  207.  
  208.     cmp    multi_count,-1        ;should we not set any?
  209.     je    just_print        ;yes, just print the current list.
  210.  
  211.     mov    ah,22            ;set_multicast_list
  212.     push    ds
  213.     pop    es
  214.     mov    di,offset our_buffer    ;ds:si -> buffer.
  215.     mov    cx,multi_count
  216.     int_pkt
  217.     call    print_error
  218.  
  219. just_print:
  220.     mov    ah,23            ;get_multicast_list
  221.     int_pkt
  222.     call    print_error
  223.  
  224.     push    ds
  225.     mov    ax,es
  226.     mov    ds,ax
  227.     mov    si,di
  228.     jmp    short print_countdown
  229. print_another_address:
  230.     push    cx
  231.  
  232.     call    print_ether_addr
  233.  
  234.     push    ds
  235.     mov    ax,cs
  236.     mov    ds,ax
  237.     mov    dx,offset crlf_msg
  238.     mov    ah,9
  239.     int    21h
  240.     pop    ds
  241.  
  242.     pop    cx
  243. print_countdown:
  244.     sub    cx,EADDR_LEN
  245.     jae    print_another_address
  246.  
  247.     pop    ds
  248.  
  249.     mov    ah,3            ;release the handle.
  250.     mov    bx,handle
  251.     int_pkt
  252.     call    print_error
  253.  
  254.     int    20h
  255.  
  256. no_signature_err:
  257.     mov    dx,offset no_signature_msg
  258.     mov    ah,9
  259.     int    21h
  260.     int    20h
  261.  
  262.  
  263. our_recv:
  264.     or    ax,ax            ;first or second call?
  265.     jne    our_recv_1        ;second -- we ignore the packet
  266.     push    cs
  267.     pop    es
  268.     mov    di,offset our_buffer
  269. our_recv_1:
  270.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  271.  
  272.  
  273.     assume    ds:code
  274.  
  275.     include    getea.asm
  276.     include    printea.asm
  277.     include    getnum.asm
  278.     include    skipblk.asm
  279.     include    getdig.asm
  280.     include    digout.asm
  281.     include    chrout.asm
  282.     include    pkterr.asm
  283.  
  284. our_buffer    label    byte
  285.  
  286. code    ends
  287.  
  288.     end    start
  289.